﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ProjectFinal
{
    public partial class Form1 : Form
    {
        public Form1()
        {
					InitializeComponent();
					dtp_Today.CustomFormat = Constants.DATE_FORMAT;  //Override date format
					BusinessRules.init(DateTime.Now.ToString(Constants.DATE_FORMAT));
        }

				protected override void OnClosing(CancelEventArgs e) {
					//BusinessRules.saveData(); //Save when exiting
					base.OnClosing(e);
				}
				
				//Add media
				private void button1_Click(object sender, EventArgs e) {
					if(radioButton1.Checked) {
						BusinessRules.newBook(textBox1.Text, textBox2.Text, textBox3.Text, MediaType.adultBook);
						BusinessRules.listBooks(listBox1);//I should handle this better.  But it works for now
					}
					if(radioButton2.Checked) {
						BusinessRules.newMedia(textBox1.Text, textBox3.Text, MediaType.DVD);
						BusinessRules.listMedia(listBox2);//I should handle this better.  But it works for now
					}
				}

        private void button2_Click(object sender, EventArgs e)
        {
            
        }

			  //add patron
				private void button3_Click(object sender, EventArgs e) {
					BusinessRules.newPatron(textBox4.Text, checkBox3.Checked);
					BusinessRules.listPatrons(listBox3);//I should handle this better.  But it works for now
				}

				//checkout
				private void button4_Click(object sender, EventArgs e) {
					int bookIndex = listBox1.SelectedIndex;
					int patronIndex = listBox3.SelectedIndex;

					if(bookIndex != -1 && patronIndex != -1)
						BusinessRules.checkOut(BusinessRules.getPatronInfo(patronIndex),
								BusinessRules.getBookInfo(bookIndex));
				}

				private void dateTimePicker1_ValueChanged(object sender, EventArgs e) {
					BusinessRules.setToday(dtp_Today.Text);
				}

				private void btn_tomorrow_Click(object sender, EventArgs e) {
					BusinessRules.setToTomorrow();
					dtp_Today.Value = BusinessRules.getToday();
				}
        
    }
}
